<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>视频广告</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../css/freevideo.css" />
    <style>

    </style>
</head>

<body>
    <div id="vm">
        <header id="aui-header">
        </header>
        <div class="video test">
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/rest.js"></script>
<script type="text/javascript" src="../../script/vue.2.5.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/video.js"></script>
<script type="text/javascript" src="../../script/playmodule.js"></script>
<script type="text/javascript" src="../../script/showdate.js"></script>
<script type="text/javascript" src="../../script/faskclick.js"></script>
<script type="text/javascript">
    var uid = $api.getStorage('uid');
    var session = $api.getStorage('session');
    var settime,videostate;
    var vm = new Vue({
                el: '#vm',
                data: {
                  daojishi: 31,
                  daojishi2: 30,
                },
                created: function() {
                    var _this = this;
                    apiready = function() {
                            api.parseTapmode();
                            var header = $api.byId('aui-header');
                            $api.fixStatusBar(header);
                            var headerPos = $api.offset(header);
                            if ('addEventListener' in document) {
                                document.addEventListener('DOMContentLoaded', function() {
                                    FastClick.attach(document.body);
                                }, false);
                            }
                            api.addEventListener({
                                name: 'guanbidaojishi'
                            }, function(ret, err) {
                              var ijkplayer = api.require('ijkplayer');
                              ijkplayer.close();
                                api.sendEvent({
                                    name: 'states'
                                });
                                // api.closeFrame({
                                //     name: 'video0'
                                // });
                                api.closeFrame();
                            });
                            api.addEventListener({
                                name: 'detialkeyback1'
                            }, function(ret, err) {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.close();
                                  api.closeFrame();
                            });
                            api.addEventListener({
                                name: 'playvideoad'
                            }, function(ret, err) {
                              _this.bofang()
                            });
                            api.addEventListener({
                                name: 'zantingvideoad'
                            }, function(ret, err) {
                              _this.zanting()
                            });
                            _this.init();
                          }
                        },
                        methods: {
                            init: function() {
                                var _this = this;
                                _this.videoinit(api.pageParam.videourl.video_ad,api.pageParam.videobg);
                            },

                            videoinit: function(advideo,videobg) {
                                var _this = this;
                                var ijkplayer = api.require('ijkplayer');
                                var systemTypeh = 210;
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.open({
                                    rect: {
                                        x: 0,
                                        y: 0,
                                        w: api.frameWidth,
                                        h: systemTypeh
                                    },
                                    styles: {
                                        head: {
                                            hide: true
                                        },
                                        foot: {
                                            hide: true
                                        }
                                    },
                                    path: advideo,
                                    // path: 'http://7o50kb.com2.z0.glb.qiniucdn.com/c1.1.mp4',
                                    autoPlay: true,
                                    movieScaling: 'scaleNone',
                                    coverImg: videobg,
                                    isFullBtn: false,
                                    isBackBtn: false,
                                    isShowTimeLable: false,
                                    isSmallOpenGesture: false,
                                    isOpenGesture: false,
                                    fixedOn: api.frameName,
                                    isAutorotate:false,
                                    fixed: true
                                });
                                api.openFrame({
                                    name: 'daojishi',
                                    url: './daojishi.html',
                                    rect: {
                                        x: api.frameWidth - 120,
                                        y: 15+api.pageParam.safetop,
                                        w: 130,
                                        h: 40
                                    }
                                });

                                api.openFrame({
                                    name: 'fanhui',
                                    url: './fanhui.html',
                                    rect: {
                                        x: 20,
                                        y: 20+api.pageParam.safetop,
                                        w: 40,
                                        h: 40
                                    },
                                    bgColor: 'rgba(0,0,0,0)',
                                });

                                videosetframe()
                            },
                            bofangtime: function() {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.getDuration(function(ret) {
                                    if (ret) {
                                        api.sendEvent({
                                            name: 'alltime',
                                            extra: {
                                                value: ret.duration,
                                            }
                                        });
                                    }
                                });
                                this.settime = setInterval(function() {
                                    ijkplayer.getCurrentPosition(function(ret) {
                                        if (ret) {
                                            api.sendEvent({
                                                name: 'positiotime',
                                                extra: {
                                                    value: ret.currentPosition,
                                                }
                                            });
                                        }
                                    });
                                }, 1000)
                            },
                            bofang: function() {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.play();
                            },
                            replay: function() {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.replay();
                            },
                            zanting: function() {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.pause();
                            },
                            full: function() {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.fullScreen();
                            },
                            unfull: function() {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.cancelFullScreen();
                            },
                            seekTo: function(ret) {
                                var ijkplayer = api.require('ijkplayer');
                                ijkplayer.seekTo({
                                    seconds: ret
                                });
                            }
                        }
                })

            function videosetframe() {
                var ijkplayer = api.require('ijkplayer');
                ijkplayer.addEventListener({
                    name: 'state'
                }, function(ret, err) {
                  console.log(JSON.stringify(ret))
                    api.sendEvent({
                        name: 'advieostase',
                        extra: {
                            eventType: ret.eventType
                        }
                    });
                    videostate = ret.eventType
                    if (ret.eventType == 'statePlaying') {
                       settime = setInterval(function() {
                          vm.daojishi = vm.daojishi - 1;
                          vm.daojishi2 = vm.daojishi;
                          if(vm.daojishi <= 0){
                            api.sendEvent({
                                name: 'settimedaojishi',
                                extra: {
                                    falg:0,
                                    daojishi: vm.daojishi2
                                }
                            });
                            clearInterval(settime)
                          }else if (vm.daojishi<10 ) {
                            vm.daojishi2= '0'+vm.daojishi;
                            api.sendEvent({
                                name: 'settimedaojishi',
                                extra: {
                                    falg:1,
                                    daojishi: vm.daojishi2,
                                    daojishi2: vm.daojishi
                                }
                            });
                          }else {
                            api.sendEvent({
                                name: 'settimedaojishi',
                                extra: {
                                    falg:1,
                                    daojishi: vm.daojishi2,
                                    daojishi2: vm.daojishi
                                }
                            });
                          }
                      }, 1000)
                    }else {
                      clearInterval(settime)
                      if(ret.eventType == 'stateComplete'){
                        api.sendEvent({
                            name: 'settimedaojishi',
                            extra: {
                                falg:0,
                                daojishi: vm.daojishi2
                            }
                        });
                      }
                    }
                    // api.openFrame({
                    //     name: 'video0',
                    //     url: './video0.html',
                    //     rect: {
                    //         x: 0,
                    //         y: 155 +api.pageParam.safetop,
                    //         w: api.frameWidth,
                    //         h: 60
                    //     }
                    // });


                })
                // //调节亮度和音量
                ijkplayer.addEventListener({
                    name: 'gesture'
                }, function(ret, err) {
                    if (ret) {
                        console.log(JSON.stringify(ret))
                        var ijkplayer = api.require('ijkplayer');
                        //靠左上滑动
                        if (ret.gestureTap == 'gestureLeftUp') {
                            ijkplayer.getBrightness(function(ret, err) {
                                if (ret) {
                                    ret.brightness = ret.brightness + 3
                                    ijkplayer.setBrightness({
                                        brightness: ret.brightness
                                    });
                                }
                            });
                            //靠左下滑动
                        } else if (ret.gestureTap == 'gestureLeftDown') {
                            ijkplayer.getBrightness(function(ret, err) {
                                if (ret) {
                                    ret.brightness = ret.brightness - 3
                                    ijkplayer.setBrightness({
                                        brightness: ret.brightness
                                    });
                                }
                            });
                            //靠右上滑动
                        } else if (ret.gestureTap == 'gestureRightUp') {
                            ijkplayer.getVolume(function(ret) {
                                if (ret) {
                                    ret.volume = Number(ret.volume) + 0.1;
                                    console.log(typeof ret.volume)
                                    if (ret.volum > 1.0) {
                                        ret.volum = 1
                                    }
                                    console.log(typeof ret.volume)
                                    ijkplayer.setVolume({
                                        volume: ret.volume
                                    });
                                }
                            });
                            //靠右上滑动
                        } else if (ret.gestureTap == 'gestureRightDown') {
                            ijkplayer.getVolume(function(ret) {
                                if (ret) {
                                    ret.volume = Number(ret.volume) - 0.1;
                                    console.log(typeof ret.volume)
                                    if (ret.volum < 0.0) {
                                        ret.volum = 0.0
                                    }
                                    console.log(ret.volume)
                                    ijkplayer.setVolume({
                                        volume: ret.volume
                                    });
                                }
                            });
                        } else if (ret.eventType == 'gestureTap') {
                            if (videostate=='statePlaying') {
                              if(api.pageParam.videoadurl){
                                  vm.zanting()
                                api.openWin({
                                    name: 'videolink_win',
                                    url: './videolink_win.html',
                                    pageParam: {
                                        videoadurl: api.pageParam.videoadurl
                                    }
                                });
                              }else {
                                api.toast({
                                    msg: '没有广告链接',
                                    duration: 2000,
                                    location: 'bottom'
                                });

                              }
                              // api.openWin({
                              //     name: 'guangaoye',
                              //     url: './guangao.html',
                              //     pageParam: {
                              //         url: api.pageParam.videourl.video_ad_url
                              //     }
                              // });
                            }else if(videostate=='stateError'){
                              api.toast({
                                  msg: '视频失败',
                                  duration: 2000,
                                  location: 'bottom'
                              });
                            }else {
                              api.toast({
                                  msg: '视频加载中',
                                  duration: 2000,
                                  location: 'bottom'
                              });

                            }
                        } else if (ret.eventType == 'stateComplete') {
                            api.sendEvent({
                                name: 'states'
                            });
                            var ijkplayer = api.require('ijkplayer');
                            ijkplayer.close();
                            // api.closeFrame({
                            //     name: 'video0'
                            // });
                            api.closeFrame();
                        }
                    }
                });
            }
</script>

</html>
